﻿#region COPYRIGHT© 2009-2012 Phillip Clark. All rights reserved.
// For licensing information see License.txt (MIT style licensing).
#endregion

using FlitBit.Parse;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FlitBit.Core.Tests
{
	/// <summary>
	/// Tests for the TokenSpec structure
	/// </summary>
	[TestClass]
	public class TokenSpecTests
	{
		public TestContext TestContext { get; set; }

		[TestMethod]
		public void MatchKeyword()
		{
			var tk = TokenSpec.MakeKeyword("this");
			var input = "this";

			Assert.AreEqual(TokenMetaKind.Keyword, tk.MetaKind);
			Assert.AreEqual(input, tk.Name);

			Cursor cursor = new Cursor(0);
			Assert.IsTrue(tk.At(input, cursor));

			Capture capture = tk.Capture(input, ref cursor);
			Assert.AreEqual(new Cursor(0), capture.Position);
			Assert.AreEqual(input.Length, capture.Length);
			Assert.AreEqual(input, capture.Value);

		}

		[TestMethod]
		public void MatchLongKeyword()
		{
			var tk = TokenSpec.MakeKeyword("thisIsALongerKeyword");
			var input = "thisIsALongerKeyword";

			Assert.AreEqual(TokenMetaKind.Keyword, tk.MetaKind);
			Assert.AreEqual(input, tk.Name);

			Cursor cursor = new Cursor(0);
			Assert.IsTrue(tk.At(input, cursor));

			Capture capture = tk.Capture(input, ref cursor);
			Assert.AreEqual(new Cursor(0), capture.Position);
			Assert.AreEqual(input.Length, capture.Length);
			Assert.AreEqual(input, capture.Value);
		}
	}
}
